import {reactive} from "vue";
import http from "../utils/http";
import {useStore} from "vuex";

const store = useStore();

const user = reactive({
    avatarStatus: false,
    editDataFormVisible: false,
    avatar: "",
    uploadDialogVisible: false,
    ordering: 'create_time',
    articleList: [],
    articleShow: '3',
    showVisible: false,
    articleID: '',
    a:'https://luffycityzhang.oss-cn-fuzhou.aliyuncs.com/uploads/',
    b: 'http://api.leleapi.cn:8000/uploads/',
    articleIMG: 'https://luffycityzhang.oss-cn-fuzhou.aliyuncs.com/uploads/',
    judgeFirst: 1,
    aliyunAvatar: '',
    bigImg: '',

    userForm: {
        nickname: "",
        signature: "",
        avatar: "",
        is_show: "1",
        gender: "",
        age: 20,
    },

    // 修改用户信息
    userData(token, userId) {
        return http.put(`/users/data/${userId}/`, this.userForm, {
            headers: {
                Authorization: `Bearer ${token}`
            }
        })
    },

    // 获取用户信息
    getUserInfo(userId) {
        return http.get(`/users/detail/${userId}/`)
    },

    // 显示用户所有文章
    getListArticle(userId) {
        return http.get(`/articles/list/${userId}/?ordering=${this.ordering}`)
    },
    // 编辑是否匿名发表
    editIsShow(ID) {
        return http.put(`/articles/upload/${ID}/`, {is_show: this.articleShow})
    },

//     删除文章
    confirmDelete(ID) {
        return http.delete(`/articles/delete/${ID}/`)
    }
})

export default user;